home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / lib / tex / inputs / equations.sty < prev    next >
Encoding:
Text File  |  1991-05-21  |  9.1 KB  |  245 lines

  1. % This file, equations.sty (July 1990), contains a collection of macros
  2. % to aid in constructing displayed equations in LaTeX.  Written by
  3. %  Charles Karney          
  4. %  Plasma Physics Laboratory      E-mail:  Karney@Princeton.EDU
  5. %  Princeton University          Phone:   +1 609 243 2607
  6. %  Princeton, NJ 08543-0451      FAX:       +1 609 243 2662
  7. % with some ideas and macros borrowed from John Hobby and Stephen Gildea.
  8.  
  9. % --------------------USER DOCUMENTATION--------------------
  10.  
  11. % Use this as a style option, e.g.,
  12. %     \documentstyle[equations]{article}
  13. % These probably don't work in conjunction with the leqno option.
  14.  
  15. % This implements the following:
  16.  
  17. % (1) \yesnumber turns on an equation number in an eqnarray* environment
  18. % (just as \nonumber turns it off in an eqnarray environment).  E.g.,
  19. %     \begin{eqnarray*}
  20. %        a &=& b \\
  21. %          & & + c \\
  22. %          & & + d \\
  23. %          & & + e \\
  24. %          & & + f \\
  25. %          & & + g \yesnumber
  26. %     \end{eqnarray*}
  27.  
  28. % (2) The eqalign environment is just like Plain TeX's \eqalign.  E.g.,
  29. %     \begin{equation}
  30. %           \begin{eqalign}
  31. %              a &= b, \\
  32. %              c &= d.
  33. %           \end{eqalign}
  34. %     \end{equation}
  35. % Note that \begin{equation} \end{equation} or equivalent is needed.
  36.  
  37. % (3) The eqalignno environment is just like Plain TeX's \eqalignno.  E.g.,
  38. %     \begin{eqalignno}
  39. %        a &= b, \label{foo}\\
  40. %        c &= d. \label{bar}
  41. %     \end{eqalignno}
  42. % Note the absence of \begin{equation} \end{equation}.  \nonumber can be used
  43. % to suppress the equation number.  eqalignno* is the same except that the
  44. % equation numbers are suppressed (unless a \yesnumber appears).
  45.  
  46. % (4) The eqaligntwo environment is a two-equation per line equivalent of
  47. % eqalignno.  E.g.,
  48. %     \begin{eqaligntwo}
  49. %        a &= b, & x &= y, \label{foo} \\
  50. %        c &= d, & z &= w. \label{bar}
  51. %     \end{eqaligntwo}
  52. % eqaligntwo* is defined similarly.
  53.  
  54. % (5) The cases environment is just like Plain TeX's \cases.  E.g.,
  55. %     \begin{equation}
  56. %        u(x) =
  57. %           \begin{cases}
  58. %             0, & for $x < 0$, \\
  59. %             1, & for $x \ge 0$.
  60. %           \end{cases}
  61. %     \end{equation}
  62. % Note the first column is treated as math, the second column as text.
  63.  
  64. % (6) I've borrowed John Hobby's modifications to the eqnarray environment
  65. % (to fix up the spacing around the operator), and to the \big, \bigg, etc.
  66. % operators (to make them scale with the point size).
  67.  
  68. % (7) I've borrowed Stephen Gildea's subequations environment, and fixed it
  69. % so that it ignores spaces after the environment and so that you can refer
  70. % both to the overall set of equations and to individual subequations.  E.g.,
  71. %     \begin{subequations} \label{foo}
  72. %       \begin{eqalignno}
  73. %          a &= b, \label{foo-a} \\
  74. %          c &= d, \label{foo-b}
  75. %       \end{eqalignno}
  76. %       text text text text ...
  77. %       \begin{equation}
  78. %          e = f. \label{foo-c}
  79. %       \end{equation}
  80. %     \end{subequations}
  81. % Now \ref{foo}, \ref{foo-a}, \ref{foo-b}, \ref{foo-c}, produce 1, 1a, 1b,
  82. % 1c.
  83.  
  84. % (8) The equation number is always printed in text mode.  Normally an
  85. % equation environment would print it in math mode (with the \rm family).
  86. % This only makes a difference if \rm in text and math modes gives you
  87. % different fonts.
  88.  
  89. % --------------------END OF USER DOCUMENTATION--------------------
  90.  
  91. % Fix up eqnarray* so that \yesnumber and \nonumber do the obvious things 
  92. % Incorporate fixes of Peter Vanroose (peter@dit.lth.se) to make \yesnumber
  93. % acutually work.
  94. \newif\if@defeqnsw \@defeqnswtrue
  95.  
  96. % This is John Hobby's (hobby@research.att.com) version to fix up the spacing.
  97. \def\eqnarray{\stepcounter{equation}\let\@currentlabel=\theequation
  98. \if@defeqnsw\global\@eqnswtrue\else\global\@eqnswfalse\fi
  99. \tabskip\@centering\let\\=\@eqncr
  100. $$\halign to \displaywidth\bgroup\hfil\global\@eqcnt\z@
  101.   $\displaystyle\tabskip\z@{##}$&\global\@eqcnt\@ne 
  102.   \hfil$\displaystyle{{}##{}}$\hfil
  103.   &\global\@eqcnt\tw@ $\displaystyle{##}$\hfil 
  104.   \tabskip\@centering&\llap{##}\tabskip\z@\cr}
  105.  
  106. \@namedef{eqnarray*}{\@defeqnswfalse\global\@eqnswfalse\eqnarray}
  107. \@namedef{endeqnarray*}{\endeqnarray}
  108.  
  109. \def\yesnumber{\global\@eqnswtrue}
  110.  
  111. \def\@@eqncr{\let\@tempa\relax\global\advance\@eqcnt by \@ne
  112.     \ifcase\@eqcnt \def\@tempa{& & & &}\or \def\@tempa{& & &}\or
  113.      \def\@tempa{& &}\or \def\@tempa{&}\else\fi 
  114.      \@tempa \if@eqnsw\@eqnnum\stepcounter{equation}\fi
  115.      \if@defeqnsw\global\@eqnswtrue\else\global\@eqnswfalse\fi
  116.      \global\@eqcnt\z@\cr}
  117.  
  118. % Several formulas like \eqalign (to go inside \begin{equation}
  119. % \end{equation} or $$ $$.
  120.  
  121. \def\@eqnacr{{\ifnum0=`}\fi\@ifstar{\@yeqnacr}{\@yeqnacr}}
  122.  
  123. \def\@yeqnacr{\@ifnextchar [{\@xeqnacr}{\@xeqnacr[\z@]}}
  124.  
  125. \def\@xeqnacr[#1]{\ifnum0=`{\fi}\cr \noalign{\vskip\jot\vskip #1\relax}}
  126.  
  127. \def\eqalign{\null\,\vcenter\bgroup\openup1\jot \m@th \let\\=\@eqnacr
  128. \ialign\bgroup\strut
  129. \hfil$\displaystyle{##}$&$\displaystyle{{}##}$\hfil\crcr}
  130. \def\endeqalign{\crcr\egroup\egroup\,}
  131.  
  132. % \cases
  133.  
  134. \def\cases{\left\{\,\vcenter\bgroup\normalbaselines\m@th \let\\=\@eqnacr
  135.     \ialign\bgroup$##\hfil$&\quad##\hfil\crcr}
  136. \def\endcases{\crcr\egroup\egroup\right.}
  137.  
  138. % Several formulas like \eqalignno (doesn't need the $$ $$)
  139.  
  140. \def\eqalignno{\stepcounter{equation}\let\@currentlabel=\theequation
  141. \if@defeqnsw\global\@eqnswtrue\else\global\@eqnswfalse\fi
  142. \let\\=\@eqncr
  143. $$\displ@@ \tabskip\@centering \halign to \displaywidth\bgroup
  144.   \global\@eqcnt\@ne\hfil
  145.   $\@lign\displaystyle{##}$\tabskip\z@skip&\global\@eqcnt\tw@
  146.   $\@lign\displaystyle{{}##}$\hfil\tabskip\@centering&
  147.   \llap{\@lign##}\tabskip\z@skip\crcr}
  148.  
  149. \def\endeqalignno{\@@eqncr\egroup
  150.       \global\advance\c@equation\m@ne$$\global\@ignoretrue}
  151.  
  152. \def\displ@@{\global\dt@ptrue\openup\jot\m@th % Remove \penalty from \displ@y
  153.   \everycr{\noalign{\ifdt@p \global\dt@pfalse
  154.       \vskip-\lineskiplimit \vskip\normallineskiplimit \fi}}}
  155.  
  156. % Here's the eqalignno* environment:
  157.  
  158. \@namedef{eqalignno*}{\@defeqnswfalse\eqalignno}
  159. \@namedef{endeqalignno*}{\endeqalignno}
  160.  
  161. % Two formulas like \eqalignno (doesn't need the $$ $$)
  162.  
  163. \def\eqaligntwo{\stepcounter{equation}\let\@currentlabel=\theequation
  164. \if@defeqnsw\global\@eqnswtrue\else\global\@eqnswfalse\fi
  165. \let\\=\@eqncr
  166. $$\displ@@ \tabskip\@centering \halign to \displaywidth\bgroup
  167.   \global\@eqcnt\m@ne\hfil
  168.   $\@lign\displaystyle{##}$\tabskip\z@skip&\global\@eqcnt\z@
  169.   $\@lign\displaystyle{{}##}$\hfil\qquad&\global\@eqcnt\@ne
  170.   \hfil$\@lign\displaystyle{##}$&\global\@eqcnt\tw@
  171.   $\@lign\displaystyle{{}##}$\hfil\tabskip\@centering&
  172.   \llap{\@lign##}\tabskip\z@skip\crcr}
  173.  
  174. \def\endeqaligntwo{\@@eqncr\egroup
  175.       \global\advance\c@equation\m@ne$$\global\@ignoretrue}
  176.  
  177. \@namedef{eqaligntwo*}{\@defeqnswfalse\eqaligntwo}
  178. \@namedef{endeqaligntwo*}{\endeqaligntwo}
  179.  
  180. % subequations
  181. %%% File: subeqn.sty
  182. %%% The subequations environment %%%
  183. %
  184. % Within the subequations environment, the only change is that
  185. % equations are labeled differently.  The number stays the same,
  186. % and lower case letters are appended.  For example, if after doing
  187. % three equations, numbered 1, 2, and 3, you start a subequations
  188. % environmment and do three more equations, they will be numbered
  189. % 4a, 4b, and 4c.  After you end the subequations environment, the
  190. % next equation will be numbered 5.
  191. %
  192. % Both text and equations can be put inside the subequations environment.
  193. %
  194. % If you make any improvements, I'd like to hear about them.
  195. %
  196. % Stephen Gildea
  197. % MIT Earth Resources Lab
  198. % Cambridge, Mass. 02139
  199. % mit-erl!gildea
  200. % gildea@erl.mit.edu
  201. %
  202. \newtoks\@stequation
  203.  
  204. \def\subequations{\refstepcounter{equation}%
  205.   \edef\@savedequation{\the\c@equation}%
  206.   \@stequation=\expandafter{\theequation}%   %only want \theequation
  207.   \edef\@savedtheequation{\the\@stequation}% %expanded once
  208.   \edef\oldtheequation{\theequation}%
  209.   \setcounter{equation}{0}%
  210.   \def\theequation{\oldtheequation\alph{equation}}}
  211.  
  212. \def\endsubequations{%
  213.   \ifnum\c@equation < 2 \@warning{Only \the\c@equation\space subequation
  214.     used in equation \@savedequation}\fi
  215.   \setcounter{equation}{\@savedequation}%
  216.   \@stequation=\expandafter{\@savedtheequation}%
  217.   \edef\theequation{\the\@stequation}%
  218.   \global\@ignoretrue}
  219.  
  220. % More from John Hobby
  221. % Fix Plain's \bigl, \Bigl, etc. macros so that they try to scale with
  222. % LaTeX size changes.  This uses the fact that \@setsize sets \ht\strutbox
  223. % to be 70% of the normal unstretched baselineskip.
  224. % (Actually it doesn't, so we have to redefine \@setsize to define \strutboxa
  225.  
  226. \newbox\strutboxa
  227. \def\@setsize#1#2#3#4{\@nomath#1\let\@currsize#1\baselineskip
  228.    #2\setbox\strutboxa\hbox{\vrule height.7\baselineskip
  229.       depth.3\baselineskip width\z@}\baselineskip\baselinestretch\baselineskip
  230.    \normalbaselineskip\baselineskip#3#4}
  231. \def\struta{\relax\ifmmode\copy\strutboxa\else\unhcopy\strutboxa\fi}
  232.  
  233. \def\big#1{{\hbox{$\left#1\vcenter to1.428\ht\strutboxa{}\right.\n@space$}}}
  234. \def\Big#1{{\hbox{$\left#1\vcenter to2.142\ht\strutboxa{}\right.\n@space$}}}
  235. \def\bigg#1{{\hbox{$\left#1\vcenter to2.857\ht\strutboxa{}\right.\n@space$}}}
  236. \def\Bigg#1{{\hbox{$\left#1\vcenter to3.571\ht\strutboxa{}\right.\n@space$}}}
  237.  
  238. % Finally, always put equation number in a box.  (Makes a difference when
  239. % text Roman is not the same as textfont0
  240.  
  241. \def\@eqnnum{\mbox{\rm (\theequation)}}
  242.  
  243. \endinput
  244.  
  245.